using System;
using System.Collections.Generic;
using System.Text;
using CMS.BIZ;
using AAM.DAL;
using AAM.BIZ;
using AAM.SQL;

namespace CMS.BOP
{
    public class SqlBizCultureProvider : SqlBizObjectProvider<BizCulture>
    {
        public BizCulture Read(string cultureCode)
        {
            Command command = Connection.CreateCommand("SELECT * FROM Cultures WHERE CultureCode=?");
            command.AddParameter(cultureCode);
            DataReader reader = command.ExecuteReader();
            BizCulture culture = null;
            if (reader.Read())
            {
                culture = CreateFromReader(reader);
            }
            reader.Close();
            command.Dispose();
            return culture;
        }
        public BizCulture Read(int cultureID)
        {
            return Read(new ObjectID(BizCulture.ObjectType, new object[] { cultureID }));
        }
        public bool Delete(int cultureID)
        {
            return Delete(new ObjectID(BizCulture.ObjectType, new object[] { cultureID }));
        }
        public override List<BizCulture> ReadAll()
        {
            return ReadAll("CultureName");
        }
        public List<BizCulture> ReadCulturesForContent(int contentID)
        {
            Command command = Connection.CreateCommand("SELECT cu.CultureID, cu.CultureName, cu.CultureCode FROM Cultures cu, Contents co WHERE co.TID=? AND cu.CultureCode=co.CultureCode ORDER BY cu.CultureName");
            command.AddParameter(contentID);
            DataReader reader = command.ExecuteReader();
            List<BizCulture> list = CreateListFromReader(reader);
            reader.Close();
            command.Dispose();
            return list;
        }
    }
}
